package com.fr.cell;

import com.fr.base.BaseUtils;
import com.fr.base.ColumnRow;
import com.fr.base.Inter;
import com.fr.cell.core.GUIConstants;
import com.fr.cell.core.GUICoreUtils;
import com.fr.cell.core.GridUtils;
import com.fr.cell.core.IntelliElements;
import com.fr.data.condition.ListCondition;
import com.fr.report.CellElement;
import com.fr.report.FloatElement;
import com.fr.report.Report;
import com.fr.report.TemplateReport;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.CellPageAttr;
import com.fr.report.cellElement.core.DSColumn;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.ReportHelper;
import com.fr.report.highlight.HighlightGroup;
import com.fr.report.painter.shape.LineShapePainter;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.SwingUtilities;

public class GridMouseAdapter
  implements MouseListener, MouseWheelListener, MouseMotionListener
{
  private static int DRAG_REFRESH_TIME = 10;
  private Grid grid;
  int oldEvtX = 0;
  int oldEvtY = 0;
  int oldLocationX = 0;
  int oldLocationY = 0;
  private long lastMouseMoveTime = 0L;
  private Map floatNamePointMap = new HashMap();

  public GridMouseAdapter(Grid paramGrid)
  {
    this.grid = paramGrid;
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
    Object localObject1;
    if (!(this.grid.isEnabled()))
      return;
    int i = paramMouseEvent.getX();
    int j = paramMouseEvent.getY();
    boolean bool1 = paramMouseEvent.isShiftDown();
    boolean bool2 = paramMouseEvent.isControlDown();
    boolean bool3 = SwingUtilities.isRightMouseButton(paramMouseEvent);
    int k = paramMouseEvent.getClickCount();
    this.grid.stopEditing();
    if ((!(this.grid.hasFocus())) && (this.grid.isRequestFocusEnabled()))
      this.grid.requestFocus();
    ReportPane localReportPane = this.grid.getReportPane();
    TemplateReport localTemplateReport = localReportPane.getEditingReport();
    this.oldEvtX = i;
    this.oldEvtY = j;
    this.grid.setDragPermited(true);
    ColumnRow localColumnRow = GridUtils.getEventColumnRow(localReportPane, i, j);
    if ((!(localReportPane.isRowEndless())) && (localColumnRow.getRow() > localTemplateReport.getRowCount() - 1))
      this.grid.setDragPermited(false);
    if ((!(localReportPane.isColumnEndless())) && (localColumnRow.getColumn() > localTemplateReport.getColumnCount() - 1))
      this.grid.setDragPermited(false);
    if (this.grid.getDrawingFloatElement() != null)
    {
      localObject1 = ReportHelper.getColumnWidthList(localTemplateReport);
      DynamicValueList localDynamicValueList = ReportHelper.getRowHeightList(localTemplateReport);
      int i1 = this.grid.getHorizontalValue();
      int i2 = this.grid.getVerticalValue();
      int i3 = ((DynamicValueList)localObject1).getValueIndex(i, i1);
      int i4 = localDynamicValueList.getValueIndex(j, i2);
      int i5 = i - ((DynamicValueList)localObject1).getRangeValue(i1, i3);
      int i6 = j - localDynamicValueList.getRangeValue(i2, i4);
      this.grid.getDrawingFloatElement().setColumn(i3);
      this.grid.getDrawingFloatElement().setLeftDistance(i5);
      this.grid.getDrawingFloatElement().setRow(i4);
      this.grid.getDrawingFloatElement().setTopDistance(i6);
      this.grid.setDataChanged(true);
      localTemplateReport.addFloatElement(this.grid.getDrawingFloatElement());
      label674: localReportPane.repaint();
    }
    else
    {
      Object localObject3;
      Object localObject4;
      if (bool3)
      {
        localObject1 = localReportPane.getGridSelection();
        int l = ((GridSelection)localObject1).getType();
        localObject3 = GridUtils.getAboveFloatElementCursor(localReportPane, i, j);
        if (localObject3 != null)
        {
          localObject4 = (FloatElement)localObject3[0];
          if (l == 1)
          {
            if (!(((GridSelection)localObject1).containFloatName(((FloatElement)localObject4).getName())))
            {
              ((GridSelection)localObject1).clearAllFloatName();
              ((GridSelection)localObject1).addFloatName(((FloatElement)localObject4).getName());
            }
          }
          else
          {
            ((GridSelection)localObject1).setType(1);
            ((GridSelection)localObject1).clearAllFloatName();
            ((GridSelection)localObject1).addFloatName(((FloatElement)localObject4).getName());
          }
        }
        else
        {
          localObject4 = GridUtils.getAdjustEventColumnRow(localReportPane, i, j);
          if (l == 1)
            GridUtils.doSelectCell(localReportPane, ((ColumnRow)localObject4).getColumn(), ((ColumnRow)localObject4).getRow());
          else if (!(((GridSelection)localObject1).containsCell(((ColumnRow)localObject4).getColumn(), ((ColumnRow)localObject4).getRow())))
            GridUtils.doSelectCell(localReportPane, ((ColumnRow)localObject4).getColumn(), ((ColumnRow)localObject4).getRow());
        }
        localReportPane.repaint();
        localObject4 = localReportPane.createPopupMenu(paramMouseEvent);
        if (localObject4 != null)
          GUICoreUtils.showPopupMenu((JPopupMenu)localObject4, this.grid, i - 1, j - 1);
      }
      else
      {
        if ((this.grid.isCellDragable()) && (this.grid.isCellSelectable()))
        {
          this.grid.setDragType(isMoveCellSelection(i, j));
          if (this.grid.getDragType() == GridUtils.DRAG_NONE)
            break label674;
          localObject1 = localReportPane.getGridSelection();
          localObject2 = ((GridSelection)localObject1).getFirstCellRectangle();
          if (this.grid.getDragRectangle() == null)
            this.grid.setDragRectangle(new Rectangle());
          this.grid.getDragRectangle().setBounds((Rectangle)localObject2);
          return;
        }
        this.grid.setDragType(GridUtils.DRAG_NONE);
        doOneClickSelection(localReportPane, i, j, bool1, bool2);
        localObject1 = GridUtils.getEventColumnRow(localReportPane, i, j);
        Object localObject2 = localTemplateReport.getCellElement(((ColumnRow)localObject1).getColumn(), ((ColumnRow)localObject1).getRow());
        if (k >= 2)
          this.grid.startEditing();
        if ((k == 1) && (localObject2 != null) && (((CellElement)localObject2).getWidget() != null))
        {
          localObject3 = ReportHelper.getColumnWidthList(localTemplateReport);
          localObject4 = ReportHelper.getRowHeightList(localTemplateReport);
          double d1 = i - ((DynamicValueList)localObject3).getRangeValue(this.grid.getHorizontalValue(), ((CellElement)localObject2).getColumn());
          double d2 = j - ((DynamicValueList)localObject4).getRangeValue(this.grid.getVerticalValue(), ((CellElement)localObject2).getRow());
          int i7 = ((DynamicValueList)localObject3).getRangeValue(((CellElement)localObject2).getColumn(), ((CellElement)localObject2).getColumn() + ((CellElement)localObject2).getColumnSpan());
          int i8 = ((DynamicValueList)localObject4).getRangeValue(((CellElement)localObject2).getRow(), ((CellElement)localObject2).getRow() + ((CellElement)localObject2).getRowSpan());
          if ((i7 - d1 > 0.0D) && (i8 - d2 > 0.0D) && (i7 - d1 < 13.0D) && (i8 - d2 < 13.0D))
            localReportPane.showWidgetWindow();
        }
        localReportPane.repaint();
      }
    }
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
    if (!(this.grid.isEnabled()))
      return;
    if (!(this.grid.isEditable()))
      return;
    boolean bool = false;
    ReportPane localReportPane = this.grid.getReportPane();
    GridSelection localGridSelection = localReportPane.getGridSelection();
    int i = localGridSelection.getType();
    if (this.grid.getDrawingFloatElement() != null)
    {
      if ((this.grid.getDrawingFloatElement().getSize().getWidth() == 0.0D) && (this.grid.getDrawingFloatElement().getSize().getHeight() == 0.0D))
        this.grid.getDrawingFloatElement().setSize(new Dimension(100, 100));
      this.grid.setDrawingFloatElement(null);
    }
    else if (i == 1)
    {
      this.grid.setCursor(Cursor.getDefaultCursor());
    }
    if (this.grid.getDragType() == GridUtils.DRAG_CELLSELECTION)
      if (i == 0)
      {
        this.grid.getReportPane().cut();
        mousePressed(paramMouseEvent);
        this.grid.getReportPane().paste();
        this.grid.setDataChanged(true);
      }
      else
      {
        bool = true;
      }
    else if (this.grid.getDragType() == GridUtils.Drag_CellSelection_BottomRight_Corner)
      if ((i == 0) && (localGridSelection.getCellRectangleCount() == 1))
      {
        int j = localGridSelection.getEditRectangle().x;
        int k = localGridSelection.getEditRectangle().y;
        int l = localGridSelection.getEditRectangle().width;
        int i1 = localGridSelection.getEditRectangle().height;
        IntelliElements.iterating(localReportPane, localGridSelection.getEditRectangle(), localGridSelection.getFirstCellRectangle(), this.grid.getDragRectangle(), bool, this.grid.isDataChanged());
        if (this.grid.getDragRectangle() != null)
        {
          localGridSelection.setOnlyCellBounds(this.grid.getDragRectangle().x, this.grid.getDragRectangle().y, this.grid.getDragRectangle().width, this.grid.getDragRectangle().height);
          localGridSelection.setEditBounds(j, k, l, i1);
        }
      }
      else
      {
        bool = true;
      }
    this.grid.setDragType(GridUtils.DRAG_NONE);
    this.grid.setDragRectangle(null);
    if (this.grid.isDataChanged())
    {
      this.grid.setDataChanged(false);
      localReportPane.fireReportDataChanged();
      localReportPane.undoRecord();
    }
    else if (bool)
    {
      localReportPane.repaint();
    }
    if (this.grid.getReportPane().isFormatBrush())
    {
      this.grid.getReportPane().brushFormat();
      this.grid.setDataChanged(true);
      if (this.grid.isDataChanged())
      {
        this.grid.setDataChanged(false);
        this.grid.getReportPane().fireReportDataChanged();
        this.grid.getReportPane().undoRecord();
      }
    }
  }

  public void mouseMoved(MouseEvent paramMouseEvent)
  {
    if (!(this.grid.isEnabled()))
      return;
    if (!(this.grid.isEditable()))
      return;
    if (this.grid.isEditing())
      return;
    long l = System.currentTimeMillis();
    if (l - this.lastMouseMoveTime <= 100L)
      return;
    this.lastMouseMoveTime = l;
    SwingUtilities.invokeLater(new Runnable(this, paramMouseEvent)
    {
      private final MouseEvent val$evt;
      private final GridMouseAdapter this$0;

      public void run()
      {
        this.this$0.mouseMoveOnGrid(this.val$evt.getX(), this.val$evt.getY());
      }
    });
  }

  public void mouseDragged(MouseEvent paramMouseEvent)
  {
    if (!(this.grid.isEnabled()))
      return;
    long l = System.currentTimeMillis();
    if (l - this.lastMouseMoveTime <= DRAG_REFRESH_TIME)
      return;
    this.lastMouseMoveTime = l;
    if ((!(this.grid.isDragPermited())) || (SwingUtilities.isRightMouseButton(paramMouseEvent)))
      return;
    ReportPane localReportPane = this.grid.getReportPane();
    threadMouseDragged(localReportPane, paramMouseEvent.getX(), paramMouseEvent.getY(), paramMouseEvent.isControlDown());
  }

  protected void threadMouseDragged(ReportPane paramReportPane, int paramInt1, int paramInt2, boolean paramBoolean)
  {
    int i1;
    int i2;
    int i10;
    int i11;
    int i12;
    int i13;
    TemplateReport localTemplateReport = paramReportPane.getEditingReport();
    GridSelection localGridSelection = paramReportPane.getGridSelection();
    int i = localGridSelection.getType();
    int j = 0;
    if (this.grid.getDrawingFloatElement() != null)
    {
      int k = Math.min(this.oldEvtX, paramInt1);
      int l = Math.max(this.oldEvtX, paramInt1);
      i1 = Math.min(this.oldEvtY, paramInt2);
      i2 = Math.max(this.oldEvtY, paramInt2);
      Object localObject3 = this.grid.getDrawingFloatElement().getValue();
      if (localObject3 instanceof LineShapePainter)
        if (((paramInt1 < this.oldEvtX) && (paramInt2 < this.oldEvtY)) || ((paramInt1 > this.oldEvtX) && (paramInt2 > this.oldEvtY)))
          ((LineShapePainter)localObject3).setPositiveArrow(false);
        else
          ((LineShapePainter)localObject3).setPositiveArrow(true);
      DynamicValueList localDynamicValueList1 = ReportHelper.getColumnWidthList(localTemplateReport);
      DynamicValueList localDynamicValueList3 = ReportHelper.getRowHeightList(localTemplateReport);
      int i6 = this.grid.getHorizontalValue();
      int i8 = this.grid.getVerticalValue();
      i10 = localDynamicValueList1.getValueIndex(k, i6);
      i11 = k - localDynamicValueList1.getRangeValue(i6, i10);
      i12 = localDynamicValueList3.getValueIndex(i1, i8);
      i13 = i1 - localDynamicValueList3.getRangeValue(i8, i12);
      this.grid.getDrawingFloatElement().setColumn(i10);
      this.grid.getDrawingFloatElement().setLeftDistance(i11);
      this.grid.getDrawingFloatElement().setRow(i12);
      this.grid.getDrawingFloatElement().setTopDistance(i13);
      this.grid.getDrawingFloatElement().setSize(new Dimension(l - k, i2 - i1));
      localGridSelection.setType(1);
      localGridSelection.clearAllFloatName();
      localGridSelection.addFloatName(this.grid.getDrawingFloatElement().getName());
      this.grid.setDataChanged(true);
      j = 1;
    }
    else
    {
      Object localObject1;
      Object localObject2;
      if (i == 1)
      {
        int i3;
        DynamicValueList localDynamicValueList2;
        int i5;
        DynamicValueList localDynamicValueList4;
        int i7;
        int i9;
        int i14;
        int i15;
        localObject1 = localGridSelection.getFloatName(0);
        localObject2 = localTemplateReport.getFloatElement((String)localObject1);
        i1 = this.grid.getCursor().getType();
        if ((i1 == 6) || (i1 == 7) || (i1 == 5) || (i1 == 4))
        {
          i2 = Math.min(this.oldEvtX, paramInt1);
          i3 = Math.max(this.oldEvtX, paramInt1);
          int i4 = Math.min(this.oldEvtY, paramInt2);
          i5 = Math.max(this.oldEvtY, paramInt2);
          DynamicValueList localDynamicValueList5 = ReportHelper.getColumnWidthList(localTemplateReport);
          DynamicValueList localDynamicValueList6 = ReportHelper.getRowHeightList(localTemplateReport);
          i10 = this.grid.getHorizontalValue();
          i11 = this.grid.getVerticalValue();
          i12 = localDynamicValueList5.getValueIndex(i2, i10);
          i13 = i2 - localDynamicValueList5.getRangeValue(i10, i12);
          i14 = localDynamicValueList6.getValueIndex(i4, i11);
          i15 = i4 - localDynamicValueList6.getRangeValue(i11, i14);
          ((FloatElement)localObject2).setColumn(i12);
          ((FloatElement)localObject2).setLeftDistance(i13);
          ((FloatElement)localObject2).setRow(i14);
          ((FloatElement)localObject2).setTopDistance(i15);
          ((FloatElement)localObject2).setSize(new Dimension(i3 - i2, i5 - i4));
        }
        else if ((i1 == 9) || (i1 == 8))
        {
          i2 = Math.min(this.oldEvtY, paramInt2);
          i3 = Math.max(this.oldEvtY, paramInt2);
          localDynamicValueList2 = ReportHelper.getRowHeightList(localTemplateReport);
          i5 = this.grid.getVerticalValue();
          i7 = localDynamicValueList2.getValueIndex(i2, i5);
          i9 = i2 - localDynamicValueList2.getRangeValue(i5, i7);
          ((FloatElement)localObject2).setRow(i7);
          ((FloatElement)localObject2).setTopDistance(i9);
          ((FloatElement)localObject2).setSize(new Dimension((int)((FloatElement)localObject2).getSize().getWidth(), i3 - i2));
        }
        else if ((i1 == 10) || (i1 == 11))
        {
          i2 = Math.min(this.oldEvtX, paramInt1);
          i3 = Math.max(this.oldEvtX, paramInt1);
          localDynamicValueList2 = ReportHelper.getColumnWidthList(localTemplateReport);
          i5 = this.grid.getHorizontalValue();
          i7 = localDynamicValueList2.getValueIndex(i2, i5);
          i9 = i2 - localDynamicValueList2.getRangeValue(i5, i7);
          ((FloatElement)localObject2).setColumn(i7);
          ((FloatElement)localObject2).setLeftDistance(i9);
          ((FloatElement)localObject2).setSize(new Dimension(i3 - i2, (int)((FloatElement)localObject2).getSize().getHeight()));
        }
        else if (i1 == 13)
        {
          i2 = this.oldLocationX + paramInt1 - this.oldEvtX;
          if (i2 < 0)
            i2 = 0;
          i3 = this.oldLocationY + paramInt2 - this.oldEvtY;
          if (i3 < 0)
            i3 = 0;
          localDynamicValueList2 = ReportHelper.getColumnWidthList(localTemplateReport);
          localDynamicValueList4 = ReportHelper.getRowHeightList(localTemplateReport);
          i7 = this.grid.getHorizontalValue();
          i9 = this.grid.getVerticalValue();
          for (i10 = 0; i10 < localGridSelection.getFloatNameCount(); ++i10)
          {
            String str = localGridSelection.getFloatName(i10);
            FloatElement localFloatElement = localTemplateReport.getFloatElement(str);
            Point localPoint = (Point)this.floatNamePointMap.get(str);
            i14 = localPoint.x + i2;
            i15 = localPoint.y + i3;
            int i16 = localDynamicValueList2.getValueIndex(i14, i7);
            int i17 = i14 - localDynamicValueList2.getRangeValue(i7, i16);
            int i18 = localDynamicValueList4.getValueIndex(i15, i9);
            int i19 = i15 - localDynamicValueList4.getRangeValue(i9, i18);
            localFloatElement.setColumn(i16);
            localFloatElement.setLeftDistance(i17);
            localFloatElement.setRow(i18);
            localFloatElement.setTopDistance(i19);
          }
        }
        this.grid.setDataChanged(true);
        j = 1;
      }
      else if (this.grid.getDragType() == GridUtils.Drag_CellSelection_BottomRight_Corner)
      {
        localObject1 = localGridSelection.getFirstCellRectangle();
        localObject2 = GridUtils.getAdjustEventColumnRow(paramReportPane, paramInt1, paramInt2);
        if (((Rectangle)localObject1).contains(((ColumnRow)localObject2).getColumn(), ((ColumnRow)localObject2).getRow()))
        {
          this.grid.getDragRectangle().setBounds((Rectangle)localObject1);
        }
        else
        {
          i1 = paramInt1 - this.oldEvtX;
          i2 = paramInt2 - this.oldEvtY;
          if (Math.abs(i2) > Math.abs(i1))
          {
            this.grid.getDragRectangle().x = ((Rectangle)localObject1).x;
            this.grid.getDragRectangle().width = ((Rectangle)localObject1).width;
            if (i2 >= 0)
            {
              this.grid.getDragRectangle().y = ((Rectangle)localObject1).y;
              this.grid.getDragRectangle().height = (((ColumnRow)localObject2).getRow() - ((Rectangle)localObject1).y + 1);
            }
            else if ((((ColumnRow)localObject2).getRow() >= ((Rectangle)localObject1).y) && (((ColumnRow)localObject2).getRow() < ((Rectangle)localObject1).y + ((Rectangle)localObject1).height))
            {
              this.grid.getDragRectangle().y = ((Rectangle)localObject1).y;
              this.grid.getDragRectangle().height = ((Rectangle)localObject1).height;
            }
            else
            {
              this.grid.getDragRectangle().y = ((Rectangle)localObject1).y;
              this.grid.getDragRectangle().height = (((Rectangle)localObject1).y - ((ColumnRow)localObject2).getRow() + ((Rectangle)localObject1).height);
            }
          }
          else
          {
            this.grid.getDragRectangle().y = ((Rectangle)localObject1).y;
            this.grid.getDragRectangle().height = ((Rectangle)localObject1).height;
            if (i1 >= 0)
            {
              this.grid.getDragRectangle().x = ((Rectangle)localObject1).x;
              this.grid.getDragRectangle().width = (((ColumnRow)localObject2).getColumn() - ((Rectangle)localObject1).x + 1);
            }
            else if ((((ColumnRow)localObject2).getColumn() >= ((Rectangle)localObject1).x) && (((ColumnRow)localObject2).getColumn() < ((Rectangle)localObject1).x + ((Rectangle)localObject1).width))
            {
              this.grid.getDragRectangle().x = ((Rectangle)localObject1).x;
              this.grid.getDragRectangle().width = ((Rectangle)localObject1).width;
            }
            else
            {
              this.grid.getDragRectangle().x = ((ColumnRow)localObject2).getColumn();
              this.grid.getDragRectangle().width = (((Rectangle)localObject1).x - ((ColumnRow)localObject2).getColumn() + ((Rectangle)localObject1).width);
            }
          }
        }
        paramReportPane.ensureColumnRowVisible(((ColumnRow)localObject2).getColumn() + 1, ((ColumnRow)localObject2).getRow() + 1);
        j = 1;
      }
      else if (this.grid.getDragType() == GridUtils.DRAG_CELLSELECTION)
      {
        localObject1 = GridUtils.getAdjustEventColumnRow(paramReportPane, paramInt1, paramInt2);
        if ((((ColumnRow)localObject1).getColumn() != this.grid.getDragRectangle().x) || (((ColumnRow)localObject1).getRow() != this.grid.getDragRectangle().y))
        {
          this.grid.getDragRectangle().x = ((ColumnRow)localObject1).getColumn();
          this.grid.getDragRectangle().y = ((ColumnRow)localObject1).getRow();
          j = 1;
        }
      }
      else if (this.grid.isCellSelectable())
      {
        localObject1 = null;
        if (paramBoolean)
          localObject1 = localGridSelection.getLastCellRectangle();
        else
          localObject1 = localGridSelection.getFirstCellRectangle();
        doShiftSelectCell(paramReportPane, paramInt1, paramInt2, (Rectangle)localObject1);
        j = 1;
      }
    }
    if (j != 0)
      this.grid.getReportPane().repaint();
  }

  protected void mouseMoveOnGrid(int paramInt1, int paramInt2)
  {
    this.grid.setToolTipText(null);
    ReportPane localReportPane = this.grid.getReportPane();
    TemplateReport localTemplateReport = localReportPane.getEditingReport();
    ColumnRow localColumnRow = GridUtils.getEventColumnRow(localReportPane, paramInt1, paramInt2);
    if (((!(localReportPane.isRowEndless())) && (localColumnRow.getRow() > localTemplateReport.getRowCount() - 1)) || ((!(localReportPane.isColumnEndless())) && (localColumnRow.getColumn() > localTemplateReport.getColumnCount() - 1)))
    {
      this.grid.setCursor(new Cursor(0));
      return;
    }
    if (localReportPane.isFormatBrush())
    {
      this.grid.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(BaseUtils.readImage("/com/fr/cell/images/cursor/formatpainter.gif"), new Point(16, 16), "formatpainter"));
    }
    else if (this.grid.getDrawingFloatElement() != null)
    {
      this.grid.setCursor(GUIConstants.DrawCursor);
    }
    else
    {
      Object[] arrayOfObject = GridUtils.getAboveFloatElementCursor(localReportPane, paramInt1, paramInt2);
      if (arrayOfObject != null)
      {
        this.grid.setCursor((Cursor)arrayOfObject[1]);
      }
      else if (this.grid.isCellSelectable())
      {
        this.grid.setCursor(GUIConstants.CellDefaultCursor);
        int i = localColumnRow.getColumn();
        int j = localColumnRow.getRow();
        CellElement localCellElement = localTemplateReport.getCellElement(i, j);
        DynamicValueList localDynamicValueList1 = ReportHelper.getColumnWidthList(localTemplateReport);
        DynamicValueList localDynamicValueList2 = ReportHelper.getRowHeightList(localTemplateReport);
        double d1 = -1.0D;
        double d2 = -1.0D;
        if (localCellElement != null)
        {
          CellGUIAttr localCellGUIAttr = localCellElement.getCellGUIAttr();
          if (localCellGUIAttr == null)
            localCellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR;
          this.grid.setToolTipText(localCellGUIAttr.getTooltipText());
          d1 = localDynamicValueList1.getRangeValue(this.grid.getHorizontalValue(), localCellElement.getColumn()) + 4;
          d2 = localDynamicValueList2.getRangeValue(this.grid.getVerticalValue(), localCellElement.getRow() + localCellElement.getRowSpan()) + 4;
          double d3 = paramInt1 - localDynamicValueList1.getRangeValue(this.grid.getHorizontalValue(), localCellElement.getColumn());
          double d4 = paramInt2 - localDynamicValueList2.getRangeValue(this.grid.getVerticalValue(), localCellElement.getRow());
          int l = 6;
          int i1 = 0;
          if ((localCellElement.getHighlightGroup() != null) && (localCellElement.getHighlightGroup().size() > 0))
          {
            if ((d3 > 0.0D) && (d4 > 0.0D) && (d3 + d4 < l))
            {
              this.grid.setCursor(new Cursor(12));
              this.grid.setToolTipText(Inter.getLocText("Condition_Attributes"));
              d1 = paramInt1 - d3 - 10.0D;
              d2 = paramInt2 - d4 - 20.0D;
            }
            ++i1;
          }
          if (localCellElement.getPresent() != null)
          {
            if ((d3 > l * i1) && (d4 > 0.0D) && (d3 + d4 < l + l * i1))
            {
              this.grid.setCursor(new Cursor(12));
              this.grid.setToolTipText(Inter.getLocText("Present"));
              d1 = paramInt1 - d3 - 10.0D;
              d2 = paramInt2 - d4 - 20.0D;
            }
            ++i1;
          }
          int i2 = localDynamicValueList1.getRangeValue(localCellElement.getColumn(), localCellElement.getColumn() + localCellElement.getColumnSpan());
          if ((localCellElement.getCellPageAttr() != null) && (((localCellElement.getCellPageAttr().isPageAfterColumn()) || (localCellElement.getCellPageAttr().isPageBeforeColumn()) || (localCellElement.getCellPageAttr().isPageAfterRow()) || (localCellElement.getCellPageAttr().isPageBeforeRow()))) && (i2 - d3 > 0.0D) && (d4 > 0.0D) && (i2 - d3 + d4 < l))
          {
            this.grid.setCursor(new Cursor(12));
            this.grid.setToolTipText(Inter.getLocText("Pagination"));
            d1 = paramInt1 - d3 + i2 - 10.0D;
            d2 = paramInt2 - d4 - 20.0D;
          }
          int i3 = localDynamicValueList2.getRangeValue(localCellElement.getRow(), localCellElement.getRow() + localCellElement.getRowSpan());
          if ((localCellElement.getWidget() != null) && (i2 - d3 > 0.0D) && (i3 - d4 > 0.0D) && (i2 - d3 < 13.0D) && (i3 - d4 < 13.0D))
          {
            this.grid.setCursor(new Cursor(12));
            this.grid.setToolTipText(Inter.getLocText("Widget"));
            d1 = paramInt1 - d3 + i2 + 10.0D;
            d2 = paramInt2 - d4 + i3 + 20.0D;
          }
          Object localObject = localCellElement.getValue();
          if ((localObject instanceof DSColumn) && (((DSColumn)localObject).getCondition() != null))
          {
            if ((((DSColumn)localObject).getCondition() instanceof ListCondition) && (((ListCondition)((DSColumn)localObject).getCondition()).getJoinConditionCount() == 0))
              break label1107:
            if ((d3 > 0.0D) && (i3 - d4 > 0.0D) && (d3 + i3 - d4 < l))
            {
              this.grid.setCursor(new Cursor(12));
              this.grid.setToolTipText(Inter.getLocText("Condition") + Inter.getLocText("Filter"));
              d1 = paramInt1 - d3 - 10.0D;
              d2 = paramInt2 - d4 + i3 + 20.0D;
            }
          }
        }
        label1107: int k = isMoveCellSelection(paramInt1, paramInt2);
        if (k == GridUtils.DRAG_CELLSELECTION)
          this.grid.setCursor(new Cursor(13));
        else if (k == GridUtils.Drag_CellSelection_BottomRight_Corner)
          this.grid.setCursor(new Cursor(1));
        if ((this.grid.getToolTipText() != null) && (this.grid.getToolTipText().length() > 0))
          this.grid.getToolTipLocation(null).setLocation(d1, d2);
      }
      else
      {
        this.grid.setCursor(Cursor.getDefaultCursor());
      }
    }
  }

  private int isMoveCellSelection(double paramDouble1, double paramDouble2)
  {
    ReportPane localReportPane = this.grid.getReportPane();
    GridSelection localGridSelection = localReportPane.getGridSelection();
    int i = localGridSelection.getType();
    if ((i == 0) && (localGridSelection.getCellRectangleCount() != 1))
      return GridUtils.DRAG_NONE;
    Rectangle localRectangle = localGridSelection.getFirstCellRectangle();
    TemplateReport localTemplateReport = localReportPane.getEditingReport();
    DynamicValueList localDynamicValueList1 = ReportHelper.getColumnWidthList(localTemplateReport);
    DynamicValueList localDynamicValueList2 = ReportHelper.getRowHeightList(localTemplateReport);
    double d1 = localDynamicValueList1.getRangeValue(this.grid.getHorizontalValue(), localRectangle.x);
    double d2 = localDynamicValueList1.getRangeValue(this.grid.getHorizontalValue(), localRectangle.x + localRectangle.width);
    double d3 = localDynamicValueList2.getRangeValue(this.grid.getVerticalValue(), localRectangle.y);
    double d4 = localDynamicValueList2.getRangeValue(this.grid.getVerticalValue(), localRectangle.y + localRectangle.height);
    if ((paramDouble1 >= d2 - 1.5D) && (paramDouble1 <= d2 + 2.5D) && (paramDouble2 >= d4 - 1.5D) && (d4 <= d4 + 2.5D))
      return GridUtils.Drag_CellSelection_BottomRight_Corner;
    double d5 = 1.0D;
    if (((paramDouble1 >= d1 - d5) && (paramDouble1 <= d1 + d5)) || ((paramDouble1 >= d2 - d5) && (paramDouble1 <= d2 + d5)))
    {
      if ((paramDouble2 < d3 - d5) || (paramDouble2 > d4 + d5))
        break label341;
      return GridUtils.DRAG_CELLSELECTION;
    }
    if (((paramDouble2 >= d3 - d5) && (paramDouble2 <= d3 + d5)) || ((paramDouble2 >= d4 - d5) && (paramDouble2 <= d4 + d5) && (paramDouble1 >= d1 - d5) && (paramDouble1 <= d2 + d5)))
      return GridUtils.DRAG_CELLSELECTION;
    label341: return GridUtils.DRAG_NONE;
  }

  private void doOneClickSelection(ReportPane paramReportPane, int paramInt1, int paramInt2, boolean paramBoolean1, boolean paramBoolean2)
  {
    Object localObject1;
    TemplateReport localTemplateReport = paramReportPane.getEditingReport();
    GridSelection localGridSelection = paramReportPane.getGridSelection();
    DynamicValueList localDynamicValueList1 = ReportHelper.getColumnWidthList(localTemplateReport);
    DynamicValueList localDynamicValueList2 = ReportHelper.getRowHeightList(localTemplateReport);
    int i = this.grid.getVerticalValue();
    int j = this.grid.getHorizontalValue();
    Object[] arrayOfObject = GridUtils.getAboveFloatElementCursor(paramReportPane, paramInt1, paramInt2);
    if (arrayOfObject != null)
    {
      Object localObject4;
      if (localGridSelection.getType() != 1)
        localGridSelection.setType(1);
      localObject1 = (FloatElement)arrayOfObject[0];
      String str = ((FloatElement)localObject1).getName();
      if ((paramBoolean1) || (paramBoolean2))
      {
        if (localGridSelection.containFloatName(str))
          localGridSelection.removeFloatName(str);
        else
          localGridSelection.addFloatName(str);
      }
      else if (!(localGridSelection.containFloatName(str)))
      {
        localGridSelection.clearAllFloatName();
        localGridSelection.addFloatName(str);
      }
      double[] arrayOfDouble = GridUtils.caculateFloatElementLocations((FloatElement)localObject1, localDynamicValueList1, localDynamicValueList2, i, j);
      int k = ((Cursor)arrayOfObject[1]).getType();
      if (k == 6)
      {
        this.oldEvtX = (int)arrayOfDouble[2];
        this.oldEvtY = (int)arrayOfDouble[3];
        break label812:
      }
      if (k == 7)
      {
        this.oldEvtX = (int)arrayOfDouble[0];
        this.oldEvtY = (int)arrayOfDouble[3];
        break label812:
      }
      if (k == 5)
      {
        this.oldEvtX = (int)arrayOfDouble[0];
        this.oldEvtY = (int)arrayOfDouble[1];
        break label812:
      }
      if (k == 4)
      {
        this.oldEvtX = (int)arrayOfDouble[2];
        this.oldEvtY = (int)arrayOfDouble[1];
        break label812:
      }
      if (k == 8)
      {
        this.oldEvtX = (int)arrayOfDouble[0];
        this.oldEvtY = (int)arrayOfDouble[3];
        break label812:
      }
      if (k == 9)
      {
        this.oldEvtX = (int)arrayOfDouble[0];
        this.oldEvtY = (int)arrayOfDouble[1];
        break label812:
      }
      if (k == 10)
      {
        this.oldEvtX = (int)arrayOfDouble[2];
        this.oldEvtY = (int)arrayOfDouble[1];
        break label812:
      }
      if (k == 11)
      {
        this.oldEvtX = (int)arrayOfDouble[0];
        this.oldEvtY = (int)arrayOfDouble[1];
        break label812:
      }
      if (k != 13)
        break label812;
      this.oldEvtX = paramInt1;
      this.oldEvtY = paramInt2;
      int l = localGridSelection.getFloatNameCount();
      int i1 = 2147483647;
      int i2 = 2147483647;
      Object localObject2 = null;
      Object localObject3 = null;
      for (int i3 = 0; i3 < l; ++i3)
      {
        str = localGridSelection.getFloatName(i3);
        localObject4 = localTemplateReport.getFloatElement(str);
        if (localObject4 == null)
          break label529:
        i1 = Math.min(i1, ((FloatElement)localObject4).getColumn());
        if (i1 == ((FloatElement)localObject4).getColumn())
          localObject3 = localObject4;
        i2 = Math.min(((FloatElement)localObject4).getRow(), i2);
        if (i2 == ((FloatElement)localObject4).getRow())
          localObject2 = localObject4;
      }
      label529: this.oldLocationX = (localDynamicValueList1.getRangeValue(j, i1) + localObject3.getLeftDistance());
      this.oldLocationY = (localDynamicValueList2.getRangeValue(i, i2) + localObject2.getTopDistance());
      this.floatNamePointMap.clear();
      i3 = 0;
      while (true)
      {
        if (i3 >= localGridSelection.getFloatNameCount())
          break label812;
        localObject4 = localGridSelection.getFloatName(i3);
        FloatElement localFloatElement = localTemplateReport.getFloatElement((String)localObject4);
        int i4 = localDynamicValueList1.getRangeValue(j, localFloatElement.getColumn()) + localFloatElement.getLeftDistance() - this.oldLocationX;
        int i5 = localDynamicValueList2.getRangeValue(i, localFloatElement.getRow()) + localFloatElement.getTopDistance() - this.oldLocationY;
        this.floatNamePointMap.put(localObject4, new Point(i4, i5));
        ++i3;
      }
    }
    if (this.grid.isCellSelectable())
    {
      localGridSelection.setType(0);
      if (paramBoolean1)
      {
        localObject1 = null;
        if (paramBoolean2)
          localObject1 = localGridSelection.getLastCellRectangle();
        else
          localObject1 = localGridSelection.getFirstCellRectangle();
        doShiftSelectCell(paramReportPane, paramInt1, paramInt2, (Rectangle)localObject1);
        break label812:
      }
      if (paramBoolean2)
      {
        doControlSelectCell(paramReportPane, paramInt1, paramInt2);
        break label812:
      }
      localObject1 = GridUtils.getEventColumnRow(paramReportPane, paramInt1, paramInt2);
      GridUtils.doSelectCell(paramReportPane, ((ColumnRow)localObject1).getColumn(), ((ColumnRow)localObject1).getRow());
      return;
    }
    localGridSelection.setType(0);
    localGridSelection.clearCellRectangles();
    localGridSelection.clearAllFloatName();
    label812: paramReportPane.fireGridSelectionChanged();
  }

  private void doShiftSelectCell(ReportPane paramReportPane, double paramDouble1, double paramDouble2, Rectangle paramRectangle)
  {
    ColumnRow localColumnRow = GridUtils.getAdjustEventColumnRow(paramReportPane, paramDouble1, paramDouble2);
    int i = localColumnRow.getColumn();
    int j = localColumnRow.getRow();
    TemplateReport localTemplateReport = paramReportPane.getEditingReport();
    GridSelection localGridSelection = paramReportPane.getGridSelection();
    Rectangle localRectangle1 = localGridSelection.getEditRectangle();
    int k = localRectangle1.x;
    int l = localRectangle1.y;
    if (localColumnRow.getColumn() >= localRectangle1.x)
      localColumnRow = ColumnRow.valueOf(localColumnRow.getColumn() + 1, localColumnRow.getRow());
    else
      ++k;
    if (localColumnRow.getRow() >= localRectangle1.y)
      localColumnRow = ColumnRow.valueOf(localColumnRow.getColumn(), localColumnRow.getRow() + 1);
    else
      ++l;
    Rectangle localRectangle2 = new Rectangle(Math.min(k, localColumnRow.getColumn()), Math.min(l, localColumnRow.getRow()), Math.max(localRectangle1.width, Math.abs(k - localColumnRow.getColumn())), Math.max(localRectangle1.height, Math.abs(l - localColumnRow.getRow())));
    localRectangle2 = this.grid.caculateIntersectsUnion(localTemplateReport, localRectangle2);
    paramRectangle.setBounds(localRectangle2.x, localRectangle2.y, localRectangle2.width, localRectangle2.height);
    paramReportPane.ensureColumnRowVisible(i, j);
  }

  private void doControlSelectCell(ReportPane paramReportPane, double paramDouble1, double paramDouble2)
  {
    TemplateReport localTemplateReport = paramReportPane.getEditingReport();
    GridSelection localGridSelection = paramReportPane.getGridSelection();
    localGridSelection.setType(0);
    ColumnRow localColumnRow = GridUtils.getAdjustEventColumnRow(paramReportPane, paramDouble1, paramDouble2);
    CellElement localCellElement = localTemplateReport.getCellElement(localColumnRow.getColumn(), localColumnRow.getRow());
    if (localCellElement == null)
    {
      localGridSelection.setEditBounds(localColumnRow.getColumn(), localColumnRow.getRow(), 1, 1);
      localGridSelection.addCellRectangle(new Rectangle(localColumnRow.getColumn(), localColumnRow.getRow(), 1, 1));
    }
    else
    {
      localGridSelection.setEditBounds(localCellElement.getColumn(), localCellElement.getRow(), localCellElement.getColumnSpan(), localCellElement.getRowSpan());
      localGridSelection.addCellRectangle(new Rectangle(localCellElement.getColumn(), localCellElement.getRow(), localCellElement.getColumnSpan(), localCellElement.getRowSpan()));
    }
    paramReportPane.ensureColumnRowVisible(localColumnRow.getColumn(), localColumnRow.getRow());
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }

  public void mouseWheelMoved(MouseWheelEvent paramMouseWheelEvent)
  {
    ReportPane localReportPane = this.grid.getReportPane();
    int i = paramMouseWheelEvent.getWheelRotation();
    localReportPane.getVerticalScrollBar().setValue(localReportPane.getVerticalScrollBar().getValue() + i * 3);
  }
}